﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace SpriteClasses
{
    public class Projectile : Sprite //  need one more projectile class for animated projectiles,
                                    //unless we go ahead and inherit from one right away (needs a decision).
    {
        protected ContentManager content;
        protected float mass;
        protected Vector2 force;
        protected Vector2 acceleration;
        protected Vector2 initialVelocity;
        public int damage;

        // the properties are useless as of now, 
        //we will figure out if we need restraints on the values being set in the future (I doubt we will need to)
        //-------------------------------------------------------------------
        public float Mass { get { return mass; } set { mass = value ; } }
        public Vector2 Force { get { return force; } set { force = value; } }
        public Vector2 Acceleration { get { return acceleration; } set { acceleration = value;} }

        // Constructor with preset origin (*it gets set in Sprite*)
        public Projectile(Texture2D textureImage, float mass, Vector2 force, Vector2 position, Vector2 velocity, float rotationSpeed,float moveSpeed, float scale, SpriteEffects spriteEffect)
            : base(textureImage,position,velocity,rotationSpeed,scale,spriteEffect,moveSpeed)
        {
            Mass = mass;
            Force = force;
 
        }
        //Constructor without preset origin
        public Projectile(Texture2D textureImage, float mass, Vector2 force, Vector2 position, Vector2 origin, Vector2 velocity, float rotationSpeed, float moveSpeed, float scale, SpriteEffects spriteEffect)
            : base(textureImage, position, velocity,origin, rotationSpeed, scale, spriteEffect, moveSpeed)
        {
            Mass = mass;
            Force = force;
        }

        // Update method for the physics of individual items
        public override void Update(GameTime gameTime, GraphicsDevice Device)
        {
            base.Update(gameTime);
            if (IsOffScreen(Device))
            {
                Active = false;
            }
            if (Active)
            {
                float timeInterval = 0;
                timeInterval += (float)gameTime.ElapsedGameTime.TotalSeconds;
                acceleration = Force / Mass;
                velocity = initialVelocity + acceleration * timeInterval;
                position += initialVelocity * timeInterval + 0.5f * acceleration * timeInterval * timeInterval;
                initialVelocity = velocity;
                timeInterval = 0;
            }
        }

        public override bool IsOffScreen(GraphicsDevice Device)
        {
            if (position.X < -TextureImage.Width * Scale ||
                position.X > Device.Viewport.Width ||
                position.Y > Device.Viewport.Height)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
